//
//  AppModel.swift
//  sui04mac
//
//  Created by 杨剑 on 2023/11/22.
//

import Foundation
import SwiftUI
import HandyJSON

struct ClusterModel {
    var cluster_id = "ebs"
    var name = "国内1"
    var base_url = "https://a1.easemob.com"
//    var base_url = "https://www.baidu.com"
}

struct AppModel :Hashable,Identifiable,HandyJSON{
    init() {
        self.id = generateID()
        
    }
    
    init(id: Int = generateID(), display_name: String = "测试", appkey: String = "<org>#<app>", client_id: String = "123", client_secret: String = "123", access_token: String = "", cluster: ClusterModel = ClusterModel()) {
        self.id = id
        self.display_name = display_name
        self.appkey = appkey
        self.client_id = client_id
        self.client_secret = client_secret
        self.access_token = access_token
        self.cluster = cluster
    }
    
    var id: Int
    var display_name : String = "测试"
    var org_name : String {
        appkey.components(separatedBy: "#").first ?? ""
    }
    var app_name : String {
        appkey.components(separatedBy: "#").last ?? ""
    }
    var appkey = "<org>#<app>"
    var client_id = "123"
    var client_secret = "123"
    var access_token = ""
    var cluster = ClusterModel()
    
    static func == (lhs: AppModel, rhs: AppModel) -> Bool {
        return lhs.id == rhs.id
    }
    func hash(into hasher: inout Hasher) {
        hasher.combine(id)
    }
}
